package ${projectConfig.beanPackage}.${config.model}.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import ${projectConfig.commPackage}.bean.PageBean;
import ${projectConfig.beanPackage}.${config.model}.bean.po.gen.${config.objectName};
import ${projectConfig.basePackage}.${config.model}.service.I${config.objectName}Service;
import ${projectConfig.commPackage}.util.OutJson;
import ${projectConfig.commPackage}.util.MyBeanUtils;
import org.apache.commons.lang3.StringUtils;

/**
 *  ${config.objectDesc}
 *
 */
@Controller
@RequestMapping("/${config.objectName?uncap_first}")
public class ${config.objectName}Controller {
	@Autowired
	private I${config.objectName}Service ${config.objectName?uncap_first}Service;
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("${config.objectName?uncap_first}:list")
	public OutJson list(Integer page, Integer limit,${config.objectName} ${config.objectName?uncap_first}){
		Map<String, Object> map = new HashMap<>();
		MyBeanUtils.copyBean2Map(map,${config.objectName?uncap_first});

		if(StringUtils.isNotEmpty(${config.objectName?uncap_first}.getSidx())&&StringUtils.isNotEmpty(${config.objectName?uncap_first}.getOrder())){
			map.put("orderBy",${config.objectName?uncap_first}.getSidx()+" "+${config.objectName?uncap_first}.getOrder());
		}
       //查询列表数据
        PageBean pageBean = ${config.objectName?uncap_first}Service.getPageBeanByMap(map, page, limit);

		return OutJson.ok().put("page", pageBean);
	}


<#list pks as prop>
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{${prop.alias}}")
	@RequiresPermissions("${config.objectName?uncap_first}:info")
	public OutJson info(@PathVariable("${prop.alias}") ${prop.javaType}  ${prop.alias}){
		${config.objectName} ${config.objectName?uncap_first} = ${config.objectName?uncap_first}Service.queryObject(${prop.alias});
		
		return OutJson.ok().put("${config.objectName?uncap_first}", ${config.objectName?uncap_first});
	}


	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("${config.objectName?uncap_first}:save")
	public OutJson save(@RequestBody ${config.objectName} ${config.objectName?uncap_first}){
		${config.objectName?uncap_first}Service.save(${config.objectName?uncap_first});
		
		return OutJson.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("${config.objectName?uncap_first}:update")
	public OutJson update(@RequestBody ${config.objectName} ${config.objectName?uncap_first}){
		${config.objectName?uncap_first}Service.update(${config.objectName?uncap_first});
		
		return OutJson.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("${config.objectName?uncap_first}:delete")
	public OutJson delete(@RequestBody ${prop.javaType} [] ${prop.alias}s){
		${config.objectName?uncap_first}Service.deleteBatch(${prop.alias}s);
		
		return OutJson.ok();
	}
</#list>
	
}
